package com.example.project;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

@RequestMapping("/user")
@RestController
public class LoginController {
    @RequestMapping("/login")
    public boolean login(String userName, String password, HttpSession session,HttpSession session2) {
        if(!StringUtils.hasLength(userName)||!StringUtils.hasLength(password)){
            return false;
        }
        if(!userName.equals("zhangsan")||!password.equals("123456")){
            return false;
        }
        session.setAttribute("userName",userName);
        //session2.setAttribute("password",password);
        return true;

    }
    @RequestMapping("/getLogin")
    public String getLogin(HttpSession session,HttpSession session2){
        String userName = (String) session.getAttribute("userName");
        //String password = (String) session2.getAttribute("password");


        if(StringUtils.hasLength(userName)){
            return userName;
        }else {
            return "";
        }
    }

}
